home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10716 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: ccn.cs.dal.ca!aa254
  2. From: aa254@ccn.cs.dal.ca (Bill Fraser)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Another What does this do...
  5. Date: 19 Mar 1996 16:06:44 GMT
  6. Organization: Chebucto Community Net
  7. Message-ID: <4imm2k$kv6@apollo.isisnet.com>
  8. References: <4ijkrh$8t@apollo.isisnet.com> <larry_kearney-1803961050310001@amaryllisp1.appsig.com>
  9. NNTP-Posting-Host: ccn.cs.dal.ca
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. To followup...
  13. I wrote <paraphased somewhat>
  14.    Given:
  15. : >         char *pb;
  16. : >         dop is structure DOP
  17.    What does this do?
  18. : >         pb = (char *)&dop;
  19.  
  20. Larry Kearney (larry_kearney@appsig.com) wrote:
  21.  
  22. : What they are doing is simply casting a pointer to the memory allocated to
  23. : dop for the structure doc_prop (represented by taking the address of dop)
  24. : into a pointer to a char. This is then assigned to pb which is a variable
  25. : defined as a pointer to a char.
  26.  
  27. : If you tried to do something like
  28.  
  29. : pb = &dop
  30.  
  31. : the compiler would complain because your are attempting to assign an
  32. : incorrect type to pb. Casting the pointer as a char eliminates this
  33. : complaint. I assume that they are attempting to access individual
  34. : char-sized pieces of the structure through pb (for copying perhaps).
  35.  
  36. : -- 
  37.  
  38. Thanks Larry, and all the others who replied directly too!  I
  39. learned two things about C this week - &, in this case, is NOT 
  40. a bit-wise AND; and casting, not the fishing variety :)
  41.  
  42. For those who wondered why a structure address was cast to a character
  43. pointer, pb, it was used later to set either a byte value:
  44.     pb[rgprop[i].offset] = (unsigned char) val;
  45. or a word value:
  46.     (*(int *) (pb+rgprop[i].offset)) = val;
  47.  
  48. Not the most obvious ( to me anyway ).
  49.  
  50. Now, do I learn enough C to modify this code to suit or do I
  51. revert to Pascal or FORTRAN?  Decisions, decisions, decisions :(
  52.  
  53. Au revoir, Bill
  54. --
  55.